package 代码记录.指定公司代码练习记录.西安.分值100分未做;

import java.util.Scanner;

/**
 * @author zx
 * @create 2023-07-09 16:03
 * 二分  (自己肯定做不出来)
 */
public class 食堂供餐 {
    private static int N;
    private static int[] P;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        int M = sc.nextInt();
        P = new int[N];
        int total = 0;
        for (int i = 0; i < N; i++) {
            P[i] = sc.nextInt();
            total += P[i];
        }
        int result = binarySearchMinSpeed(total, M);
        System.out.println(result);
    }

    private static int binarySearchMinSpeed(int total, int M) {
        int left = 0;
        int right = total - M;
        int result = right;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (canDeliver(mid, M)) {
                result = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return result;
    }

    private static boolean canDeliver(int speed, int foods) {
        for (int i = 0; i < N; i++) {
            foods -= P[i];
            if (foods < 0) {
                return false;
            }
            foods += speed;
        }
        return true;
    }
}
